package org.finesys.gateway.router;

import org.finesys.gateway.handler.AjImageCodeCheckHandler;
import org.finesys.gateway.handler.AjImageCodeCreateHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 验证码路由
 */
@Configuration
public class CaptchaRouter {

    @Bean
    public RouterFunction<ServerResponse> captchaRouterFunction(AjImageCodeCreateHandler ajImageCodeCreateHandler, AjImageCodeCheckHandler ajImageCodeCheckHandler) {
        return RouterFunctions.route(RequestPredicates.path("/gateway/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), ajImageCodeCreateHandler)
                .andRoute(RequestPredicates.path("/gateway/code/check").and(RequestPredicates.accept(MediaType.ALL)), ajImageCodeCheckHandler);
    }
}
